﻿<!--#include file=commons.asp-->

<%
	Response.Charset = "UTF-8"
	action = Request("action")
	Dim msg

	Select Case action
		Case 1
			Session.Contents.Remove("user")
		
		Case 2
			msg = "Sessão expirada"
	End Select
%>
<html>
	<head>
		<title>Controle Financeiro Doméstico</title>
	</head>
	
	<body style="font-family:arial;">
	
		<script type="text/javascript">
			$(document).ready(function(){
				$("#btnLogin").click(function(){
					login();
				});
				
				$("#txtId").keypress(function(event){
					if(event.which == 13){
						$("#txtSenha").focus();
					}
				});
				
				$("#txtSenha").keypress(function(event){	
					if(event.which == 13){
						login();
					}
				});
				
				$("#txtId").focus();
			});
			 
			function login(){
				if($.trim($("#txtId").val()) == "" || $.trim($("#txtSenha").val()) == ""){
					$("#divMsg").html("Entre com o usuário e senha.");
					$("#txtId").focus();
					return;
				}
			
				$.ajax({
					type: "POST",
					url: "functions.asp",
					data: {
						"action": "1",
						"login": $("#txtId").val(),
						"pass": "123"
					},
					success: function(data){
						//Verificando alguma inconsistência no retorno
						if(data.substring(0, 2) == "-1"){
							$("#divMsg").html(data.substring(2, data.length));
							$("#txtId").focus();
						}else{
							location = data;
						}
					},
					error: function(XMLHttpRequest, textStatus, errorThrown){												
						alert("Ocorreu um erro.\r " + errorThrown);
						return false;
					}
				});	
			}
			 

		</script>
	
		<div style="text-align: center; font-size: 17px; margin-top: 50px; width: 300px; position: absolute; left:50%; margin-left: -150px;">
			Controle <b>Fin</b>anceiro Doméstico
		</div>
	
		<table style="text-align: center; font-size: 13px; border: black 1px solid; padding: 10px; width: 150px; position: absolute; left:50%; margin-left: -75px; margin-top: 150px">
			<tr><td>Usuário</td></tr>
			
			<tr>
				<td><input id="txtId" type="text" style="width: 100px;" maxlength="6" /></td>
			</tr>
			
			<tr><td>&nbsp</td></tr>
			
			<tr><td>Senha</td></tr>
			
			<tr><td style="margin:bottom: "><input id="txtSenha" type="password" style="width: 100px;" maxlength="6" /></td></tr>
			
			<tr>
				<td style="text-align:center;"><input id="btnLogin" type="button" value="Ok" /></td>
			</tr>
			
			<tr>
				<td><div id="divMsg" style="color: red; margin-top: 10px;"><% response.write msg %></div></td>
			</tr>
		</table>		
	</body>
</html>